package Tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者:hfj
 * 功能:145.二叉树的后序遍历
 * 日期: 2025/10/27 16:41
 */
public class PostorderTraversal {

    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();

        PostOrder(root,list);
        return list;
    }

    public void PostOrder(TreeNode root, List<Integer> list) {
        if (root != null){
            PostOrder(root.left,list);
            PostOrder(root.right,list);
            list.add(root.val);
        }
    }
}
